<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<title>setState | STATE_DISABLE | STATE_ENABLE</title>
		<script type="text/javascript" src="../load_lufylegend.js"></script>
		<script type="text/javascript" src="../load_lufylegend.ui.js"></script>
	</head>
	<body>
			<div id="legend">
			</div>
			<script>
			LInit(20, "legend", 800, 480, main);
var backLayer;
var sound;
var nowTime;
var ss = false;
function main(){
	LGlobal.setDebug(true);
	sound = new LSound();
	sound.addEventListener(LEvent.COMPLETE,gameInit);
	backLayer = new LSprite();
	addChild(backLayer);
	LGlobal.ios =true, LGlobal.canTouch = true;
	if(LGlobal.ios && LGlobal.canTouch){
		var button01 = new LButtonSample1("点击开始读取音乐文件");
		button01.x = 10;
		button01.y = 10;
		backLayer.addChild(button01);
		button01.addEventListener(LMouseEvent.MOUSE_UP,onloadSound);
	}else{
		onloadSound(null);
	}
}
function onloadSound(e){
	backLayer.removeAllChild();
	var url = "http://lufylegend.com/media/LSound/kfighter.";
	//sound.load(url+"mp3,"+url+"wav,"+url+"ogg");
	var myMp3 = "http://lufylegend.com/demo/RunningGirl/sound/jump.mp3";
	sound.load(myMp3);
}
function gameInit(e){
	sound.removeEventListener(LEvent.COMPLETE,gameInit);
	sound.play(0,3);
	nowTime = new LTextField();
	nowTime.x = 100;
	nowTime.y = 50;
	backLayer.addChild(nowTime);
	nowTime.text = "00:00:00";
	backLayer.addEventListener(LEvent.ENTER_FRAME,onframe);
	backLayer.addEventListener(LMouseEvent.MOUSE_UP,onup);
}	
function onup(e){
	if(e.offsetX > 30 && e.offsetX < 60 && e.offsetY > 0 && e.offsetY < 30){
		if(sound.playing){
			sound.stop();
		}else{
			sound.play();
		}
	}else if(e.offsetX > 200 && e.offsetX < 350 && e.offsetY > 50 && e.offsetY < 90){
		//trace("sound.setVolume("+((e.offsetX - 200)/150)+")");
		sound.setVolume((e.offsetX - 200)/150);
	}
}
var xe = 0;
function onframe(){
	backLayer.graphics.clear();
	backLayer.graphics.drawRect(2,"#000000",[20,0,440,100]);
	backLayer.graphics.drawRect(1,"#000000",[70,10,380,30]);
	var sec = sound.getCurrentTime() % 60 >>>0;
	if(sec < 10)sec="0"+sec;
	var min = (sound.getCurrentTime() / 60)>>>0;
	if(min < 10)min="0"+min;
	nowTime.text = "00:"+min+":"+sec;
	backLayer.graphics.drawRect(1,"#000000",[70,10,380*(sound.getCurrentTime()/sound.length)>>>0,30],true,"#000000");
	if(sound.playing){
		backLayer.graphics.drawRect(2,"#000000",[30,10,10,30],true,"#000000");
		backLayer.graphics.drawRect(2,"#000000",[45,10,10,30],true,"#000000");
	}else{
		backLayer.graphics.drawVertices(1,"#000000",[[30,10],[60,25],[30,40]],true,"#000000");
	}
	for(var i=0;i<10;i++){
		var sx = 200 + i*15;
		var sy = 40 - i*4;
		if(sound.getVolume() > i*0.1){
			backLayer.graphics.drawRect(1,"#000000",[sx,50,10,40-sy],true,"#000000");
		}else{
			backLayer.graphics.drawRect(1,"#000000",[sx,50,10,40-sy]);
		}
	}
}
			</script>
	</body>
</html>